package com.dailyblue.java.spring.cloud.example.gateway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.List;


@Slf4j
@Component
public class TokenGlobalFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        log.info("进入到了全局token过滤器,准备获取header中的数据");
        HttpHeaders httpHeaders = exchange.getRequest().getHeaders();
        List<String> list = httpHeaders.get("token");
        log.info("token的内容是:{}", list);
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
